use "$project_path/data/4_regdata/robustness/regdata_with_inconsequential", clear

gen inconsequential_election = (flag_inconsequential==1 | flag_coup==1)

rdrobust inconsequential_election runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot inconsequential_election runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) legend(off) title("Probability of inconsequential election", size(large) placement(9) span))) 
graph export "$project_path/output/appendix_figures/Appendix_Figure_C1.pdf", as(pdf) name("Graph") replace
